package com.zb.service.impl;
import com.zb.mapper.UsersMapper;
import com.zb.entity.Users;
import org.springframework.stereotype.Service;
import com.zb.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.zb.util.PageUtil;
import java.util.ArrayList;
import java.util.HashMap;

@Service
public class UsersServiceImpl implements UsersService {

    @Autowired
    private UsersMapper usersMapper;

    public Users getUsersById(Long id)throws Exception{
        return usersMapper.getUsersById(id);
    }

    public List<Users>	getUsersListByMap(Map<String,Object> param)throws Exception{
        return usersMapper.getUsersListByMap(param);
    }

    public Integer getUsersCountByMap(Map<String,Object> param)throws Exception{
        return usersMapper.getUsersCountByMap(param);
    }

    public Integer qdtxAddUsers(Users users)throws Exception{
            //users.setCreatedTime(new Date());
            return usersMapper.insertUsers(users);
    }

    public Integer qdtxModifyUsers(Users users)throws Exception{
        //users.setUpdatedTime(new Date());
        return usersMapper.updateUsers(users);
    }

    public Integer qdtxDeleteUsersById(Long id)throws Exception{
        return usersMapper.deleteUsersById(id);
    }

    public PageUtil<Users> queryUsersPageByMap(Map<String,Object> param,Integer index,Integer size)throws Exception{
        param.put("start",(index-1)*size);
        param.put("size", size);

        List<Users> usersList = usersMapper.getUsersListByMap(param);
        Integer count = usersMapper.getUsersCountByMap(param);

        PageUtil<Users> page = new PageUtil<Users>();
        page.setData(usersList);
        page.setIndex(index);
        page.setSize(size);
        page.setCount(count);
        return page;
    }

    public Integer qdtxBatchDeleteUsers(String ids)throws Exception{
        Map<String,List<String>> param=new HashMap<String,List<String>>();
        String[] paramArrays=ids.split(",");
        List<String> idList=new ArrayList<String>();
            for (String temp:paramArrays){
                idList.add(temp);
            }
        param.put("ids",idList);
        return usersMapper.batchDeleteUsers(param);
    }


}
